package com.jdz.gxq.info.admin.landinfo.service;

import java.util.List;
import java.util.Map;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

import com.jdz.gxq.info.admin.landinfo.bo.Landinfo;

public class LandinfoServiceImpl implements LandinfoService {

	private QueryDAO queryDAO = null;

	private UpdateDAO updateDAO = null;

	/**
	 * Landinfo检索分页用，查询记录条数
	 * 
	 * @return
	 */
	public int getLandinfosCount(String enterpriseName) {

		int totalCount = queryDAO.executeForObject(
				"landinfo.getLandinfosCount", enterpriseName, Integer.class);

		return totalCount;
	}

	/**
	 * Landinfo检索
	 * 
	 * @return
	 */
	public List<Landinfo> getLandinfos(Map<String, Object> params) {

		return queryDAO.executeForObjectList("landinfo.getLandinfos", params);
	}

	/**
	 * 追加Landinfo
	 * 
	 * @param landinfo
	 */
	public void insertLandinfo(Landinfo landinfo) {

		updateDAO.execute("landinfo.insertLandinfo", landinfo);
	}

	/**
	 * 更新Landinfo
	 * 
	 * @param landinfo
	 */
	public void updateLandinfo(Landinfo landinfo) {

		updateDAO.execute("landinfo.updateLandinfo", landinfo);
	}

	/**
	 * 通过id得到landinfo
	 * 
	 * @param id
	 * @return
	 */
	public Landinfo getLandinfoById(int id) {

		Landinfo landinfo = queryDAO.executeForObject(
				"landinfo.getLandinfoById", id, Landinfo.class);

		return landinfo;
	}

	/**
	 * 删除Landinfo
	 * 
	 * @param landinfo
	 */
	public void deleteLandinfo(int id) {

		updateDAO.execute("landinfo.deleteLandinfoById", id);
	}

	/**
	 * 验证landinfoName是否重复 flag: 1 追加时验证 flag: 2 更新时验证
	 */
	public boolean checkLandinfoName(Landinfo paramLandinfo, int flag) {

		Landinfo landinfo = queryDAO.executeForObject(
				"landinfo.getLandinfoByName", paramLandinfo.getProjectName(),
				Landinfo.class);

		if (landinfo == null) {
			return true;
		}

		// 更新验证，查出来的数据是不是本身
		if (flag == 2) {

			if (landinfo.getId() == paramLandinfo.getId()) {
				return true;
			}
		}

		return false;
	}

	public void setQueryDAO(QueryDAO queryDAO) {
		this.queryDAO = queryDAO;
	}

	public void setUpdateDAO(UpdateDAO updateDAO) {
		this.updateDAO = updateDAO;
	}

}
